import Vue from 'vue'
import VueRouter from 'vue-router'


import layout from "@/views/layout/layout.vue";
import login from "@/views/login/login.vue";
import register from "@/views/login/register.vue";
import userInfo from "@/views/user/userInfo.vue";
import dashBoard from "@/views/layout/dashBoard.vue";

Vue.use(VueRouter)

const routes = [{
    path: '/login', name: "Login", component: login
}, {
    path: '/', name: "Layout", component: layout, redirect: '/dashBoard', children: [{
        path: '/dashBoard', name: "DashBoard", component: dashBoard
    }, {
        path: '/userInfo', name: "UserInfo", component: userInfo
    }]
}, {
    path: "/register", name: "Register", component: register
}
    // {
    //     path: '/about',
    //     name: 'about',
    //     // route level code-splitting
    //     // this generates a separate chunk (about.[hash].js) for this route
    //     // which is lazy-loaded when the route is visited.
    //     component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
    // }
]
// 防止连续点击多次路由报错
let routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
    routes, mode: "history", scrollBehavior: () => ({y: 0}),
})

export default router
